package com.baozun.houji.me.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
import com.alibaba.android.arouter.facade.annotation.Route
import com.baozhun.mall.common.arouter.RoutePath
import com.baozhun.mall.common.base.BaseActivity
import com.baozun.houji.me.R
import com.baozun.houji.me.databinding.ActivityChatBinding
import com.baozun.houji.me.fragment.ChatFragment
import com.baozun.houji.me.viewmodel.ChatViewModel
import com.hjq.bar.TitleBar

/**
 * @Title：聊天页面
 * @Description：
 * @Author：xuefeng.zhu
 * @Since：2022/11/4
 * @Version：1.0.0
 */
@Route(path = RoutePath.Me.CHAT)
class ChatActivity : BaseActivity<ChatViewModel, ActivityChatBinding>() {
    private val mChatFragment by lazy { ChatFragment.newInstance() }

    companion object {
        fun start(context: Context) {
            var intent = Intent(context, ChatActivity::class.java)
            context.startActivity(intent)
        }
    }

    override fun initView(savedInstanceState: Bundle?) {
        val manager: FragmentManager = supportFragmentManager
        val transaction: FragmentTransaction = manager.beginTransaction()
        transaction.replace(R.id.container, mChatFragment)
        transaction.commitAllowingStateLoss()
    }

    override fun createObserver() {

    }

    override fun onLeftClick(titleBar: TitleBar?) {
        when (titleBar?.leftIconAction) {
            TitleBar.ACTION_ICON_CLICK_BACK -> {
                if (mChatFragment.mDataBinding.chatWebView.canGoBack()) {
                    mChatFragment.mDataBinding.chatWebView.goBack()
                } else {
                    finish()
                }

            }
        }
    }
}